import { createStore } from "vuex";
import createPersistedState from "vuex-persistedstate";
export default createStore({
  state: {
    API_BASE_URL: process.env.VUE_APP_API_BASE_URL, //服务器地址
    isGetterRouter: false, //是否已加载过动态路由
    isCollapsed: false, //侧边栏的是否收缩
    userInfo: {}, //用户信息
  },
  getters: {},
  mutations: {
    changeGetterRouter(state, value) {
      state.isGetterRouter = value;
    },
    // 控制侧边栏的展开和收缩
    changeCollapse(state) {
      state.isCollapsed = !state.isCollapsed;
    },
    // 存储用户信息
    changeUserInfo(state, value) {
      state.userInfo = {
        ...state.userInfo,
        ...value,
      };
    },
    // 清除用户信息
    clearUserInfo(state, value) {
      state.userInfo = {};
    },
  },
  actions: {},
  modules: {},
  plugins: [
    createPersistedState({
      paths: ["isCollapsed", "userInfo"], //控制是否持久化
    }),
  ],
});
